package com.kuang.controller;
import com.kuang.pojo.Books;
import com.kuang.pojo.Students;
import com.kuang.pojo.Teachers;
import com.kuang.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    @Qualifier("TeacherServiceImpl")
    private TeacherService teacherService;

    @RequestMapping("/toAddTeacher")
    public String toAddTeacher(){
        return "addTeacher";
    }

    @RequestMapping("addTeacher")
    public String addTeacher(Teachers teacher){
        teacherService.addTeacher(teacher);
        return "redirect:/teacher/allTeacher";
    }


    @RequestMapping("/allTeacher")
    public String list(Model model){
        List<Teachers> list = teacherService.queryAllTeacher();
        model.addAttribute("list", list);
        return "allTeacher";
    }

    @RequestMapping("/toUpdateTeacher")
    public String toUpdateBook(Model model, int Tid) {
        Teachers teacher = teacherService.queryTeacherByTid(Tid);
        model.addAttribute("teacher",teacher );
        return "updateTeacher";
    }

    @RequestMapping("/updateTeacher")
    public String updateBook(Model model, Teachers teacher) {
        teacherService.updateTeacher(teacher);
        Teachers teachers = teacherService.queryTeacherByTid(teacher.getTid());
        model.addAttribute("teachers", teachers);
        return "redirect:/teacher/allTeacher";
    }

    @RequestMapping("/del/{Tid}")
    public String deleteTeacherByTid(@PathVariable("Tid") int Tid){
        teacherService.deleteTeacherByTid(Tid);
        return "redirect:/teacher/allTeacher";
    }

    @RequestMapping("/teacherIndex")
    public String studentIndex(Model model, int teacherTid){
        Teachers teacher = teacherService.queryTeacherByTid(teacherTid);



        model.addAttribute("teacher", teacher);

        return "teacherIndex";
    }

    @RequestMapping("/teacherSalary")
    public String salaryList(Model model){
        List<Teachers> list = teacherService.queryAllTeacher();
        model.addAttribute("list", list);
        return "teacherSalary";
    }



}
